package cn.com.djin.ssm.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.djin.ssm.entity.Address;
import cn.com.djin.ssm.service.AddressService;

/**
* @author 作者:djin
* QQ： 502037675
* @version 创建时间：2018年9月15日 下午3:00:44
* 类说明：
*/
@Service
@Transactional
public class AddressServiceImpl extends BaseServiceImpl<Address> implements AddressService{

	//添加默认地址
	@Override
	public String saveCheckedAddress(Address address) {
		Address pramAddress = new Address();
		pramAddress.setAtype(1);
		pramAddress.setUser(address.getUser());
		try {
			Address oldAddress = addressMapper.queryObjectByPramas(pramAddress);
			if(oldAddress!=null){
				pramAddress.setAid(oldAddress.getAid());
				pramAddress.setAtype(2);
				addressMapper.updateByPramas(pramAddress);
			}
			addressMapper.insert(address);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return FAIL;
		}
		
	}
	
	
}
